#ifndef REQUESTHANDLERTHREADPOOL_H
#define REQUESTHANDLERTHREADPOOL_H

#include <QMutexLocker>
#include <QList>
#include <QMutex>

#include <QThread>

class RequestHandlerThread;
class PurgeHandlerThread2;

class RequestHandlerThreadPool
{
public:

    static RequestHandlerThreadPool* getInstance()
    {
        QMutexLocker locker(&m_mutex);
        if(m_instance == NULL)
        {
            m_instance = new RequestHandlerThreadPool();
        }
        return m_instance;
    }

    RequestHandlerThreadPool();

    ~RequestHandlerThreadPool();

    int addHandlerThread(RequestHandlerThread* thread);

    int removeHandlerThread(RequestHandlerThread* thread);

    RequestHandlerThread *getHandlerThread(const std::string request_id);

    QList<RequestHandlerThread*> *getThreadList() const
    {
        return m_runningThreadList;
    }

private:

    void purgeStopThread();

    static RequestHandlerThreadPool *m_instance;

    static QMutex m_mutex;

   // QMap<unsigned int, ResponseHandlerThreadPool*> *m_runningThreadList;

    QList<RequestHandlerThread*> *m_runningThreadList;

    PurgeHandlerThread2 *m_purgeThread;



};

class PurgeHandlerThread2 : public QThread
{
public:
    PurgeHandlerThread2();

    ~PurgeHandlerThread2();

    void run();

    void setStop(bool stop)
    {
        m_stop = stop;
    }

private:

    bool m_stop;
};
#endif
